#!/bin/bash

# 定义变量方便修改
table_db=cy_database 
hive=/home/software/hive-2.3.6/bin/hive

# 如果是输入的日期按照取输入日期；如果没输入日期取当前时间的前一天
if [ -n "$1" ] ;then
	do_date=$1
else 
	do_date=`date -d "-1 day" +%F`  
fi 

sql="
with
tmp_enterprise_business as 
(
	select
		eb.id,
		eb.ent_id,
		eb.ent_name,
		ee.short_name,
		ee.social_security_number,
		ee.industry_code,
		ee.business_code,
		ee.business_nature_code,
		ee.industry_type,
		ee.business_type,
		ee.business_nature,
		ee.uniform_social_credit_code,
		ee.scale,
		ee.scale_code,
		ee.financing_stage,
		ee.registered_capital,
		ee.registration_authority,
		ee.establishment,
		ee.introduction,
		eb.turnover,
		eb.turnover_profit,
		eb.market_value,
		eb.risk_info,
		eb.warning_info,
		eb.registered_capital_update,
		eb.alter_time

	from cy_database.dwd_enterprise_business eb
	join cy_database.dwd_enterprise ee
	on eb.ent_name= ee.ent_name
	where  eb.dt='2020-06-17' and eb.id is not null and ee.dt='2020-06-17' and ee.id is not null

)
insert overwrite table cy_database.dws_enterprise_business_detail partition(dt='2020-06-17')
	select
		id,
		ent_id,
		ent_name,
		short_name,
		social_security_number,
		industry_code,
		business_code,
		business_nature_code,
		industry_type,
		business_type,
		business_nature,
		uniform_social_credit_code,
		scale,
		scale_code,
		financing_stage,
		registered_capital,
		registration_authority,
		establishment,
		introduction,
		turnover,
		turnover_profit,
		market_value,
		risk_info,
		warning_info,
		registered_capital_update,
		alter_time
	from tmp_enterprise_business

;



"
$hive -e "$sql"